/**
 * Created by rockyren on 14-8-27.
 */
/**
 * @class 调色板类
 */

define(function(require,exports,module){
  var cfg = require("./config");


  /**
   * @constructor 调色板构造器
   */
  function ColorPanel() {
    //以数组的形式增加颜色键
    this.buttonGroup = [new ButtonColor('#87318C','小伟紫'),
      new ButtonColor('#FF6699','脑残粉')]
    this._setButton();
    this._buttonClick();
  }
  module.exports = ColorPanel;

  /**
   * @method 根据以上数组增加颜色键
   * @private
   */
  ColorPanel.prototype._setButton = function() {
    for(var i=0;i<this.buttonGroup.length;i++) {
      curButtonColor = this.buttonGroup[i];

      $button = $('<button type="button" class="btn btn-primary">' + curButtonColor.name + '</button>');
      $button.appendTo('#color-choice');
      $button.css({
        'background-color':curButtonColor.color,
        'color':'white',
        'margin-right': '3px'

      });


    }
  };

  /**
   * @method 按钮点击事件:添加selected样式;设置当前颜色
   * @private
   */
  ColorPanel.prototype._buttonClick = function() {
    $('#setting button').click(function(){
      $('.select').removeClass('select');
      $(this).addClass('select');
      cfg.fillColor = $(this).css("background");
    });

  };

  /**
   * @innerClass 颜色+名字类
   * @param color 十六进制颜色
   * @param name 颜色名
   * @constructor
   */
  function ButtonColor(color,name) {
    this.color = color;
    this.name = name;
  }

});

